package edu.ufop.vaadin.helloworld.view;

import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;

@SuppressWarnings("serial")
public class WelcomeView extends CustomComponent implements View {

	public static final String NAME = "";

	Label text = new Label();
	
	Button disc = new Button("Cadastrar Disciplina", new Button.ClickListener() {

		@Override
		public void buttonClick(ClickEvent event) {
				// Refresh this view, should redirect to login view
			getUI().getNavigator().navigateTo(CadastrarDisciplina.NAME);
		}
	});
	
	Button prof = new Button("Cadastrar Professor", new Button.ClickListener() {

		@Override
		public void buttonClick(ClickEvent event) {
				// Refresh this view, should redirect to login view
			getUI().getNavigator().navigateTo(CadastrarProfessor.NAME);
		}
	});
	
	Button alu = new Button("Cadastrar Aluno", new Button.ClickListener() {

		@Override
		public void buttonClick(ClickEvent event) {
				// Refresh this view, should redirect to login view
			getUI().getNavigator().navigateTo(CadastrarAluno.NAME);
		}
	});

	Button logout = new Button("Logout", new Button.ClickListener() {

		@Override
		public void buttonClick(ClickEvent event) {

			// "Logout" the user
			getSession().setAttribute("user", null);

			// Refresh this view, should redirect to login view
			getUI().getNavigator().navigateTo(NAME);
		}
	});

	public WelcomeView() {
		setCompositionRoot(new CssLayout(text, logout,alu, disc,prof));
	}

	@Override
	public void enter(ViewChangeEvent event) {
		// Get the user name from the session
		String username = String.valueOf(getSession().getAttribute("user"));

		// And show the username
		text.setValue("Hello " + username);
	}
}